package zb.jwt;

import io.jsonwebtoken.*;

import java.util.Date;

public class Testjwt {
    public static void main(String[] args) {
        //createJwt();
        parseJwt();
    }
    //生成Jwt
    public static void createJwt(){
        JwtBuilder jwtBuilder= Jwts.builder();
        jwtBuilder.setId("123");
        jwtBuilder.setSubject("{'uid':1,'username':admin}");
        jwtBuilder.setIssuedAt(new Date());
        jwtBuilder.setExpiration(new Date(System.currentTimeMillis()+60*3000));//3分钟
        jwtBuilder.signWith(SignatureAlgorithm.HS256,"wf16");//签名，密钥
        System.out.println(jwtBuilder.compact());
    }
    //解析jwt
    public static void parseJwt(){
        String token="";
        JwtParser parser=Jwts.parser();
        parser.setSigningKey("wf16111");
        Claims claims=parser.parseClaimsJws(token).getBody();
        System.out.println(claims);
    }

}
